$(document).ready(function(){

	$.ajax({
  		type: "post",
 		url: "hmk/getWukuType_getWukuType.action",
  		success:function(data){
  			$.each(data.typeList,function(i,n){
  				$("<option value="+n.tpyeId+">"+n.tpyeName+"</option>").appendTo('#wukutype_id');
			});
  		}
	});
	
	/////////////////////
	$("#acceptForm").validate({
		submitHandler: function(form){   //表单提交句柄,为一回调函数，带一个参数：form  
            //form.submit();   //提交表单
            var typeID=$('#wukutype_id option:selected').val();
			var teamname=$('#teamName_ID').val();
			var teamscale=$('#teamscale_ID').val();
			var teamContact=$('#teamContact_ID').val();
			var teamTel=$('#teamTel_ID').val();
			var teamLocation=$('#teamLocation_ID').val();
			var teamDepart=$('#teamDepart_ID').val();
			var teamDuty=$('#teamDuty_ID').val();
			
			$.ajax({
  			type: "post",
 			url: "hmk/saveTeam_saveTeam.action",
 			data:{
 				  teamName1:teamname,teamDuty1:teamDuty,typeID:typeID,teamContact1:teamContact,
 				  teamDepart1:teamDepart,teamLocation1:teamLocation,teamScale1:teamscale,teamTel1:teamTel
 				 },
  			success:showData
		 });
		  
        },
		rules: {
			'wukutype_id':'required',
			'teamName_ID':'required',
			'teamDepart_ID':'required',
			'teamDuty_ID':'required',
			'teamLocation_ID':'required',
			'teamscale_ID':{
				required:true,
				digits:true
			},
			'teamTel_ID':{
				digits:true,
       		 	minlength:1,
       		 	maxlength:11
			}
			
		} ,
		messages: {
			'wukutype_id':"*必须选",
			'teamName_ID':"*必须选",
			'teamDepart_ID':"*必须选",
			'teamDuty_ID':"*必须选",
			'teamLocation_ID':'*必须选',
			'teamscale_ID':{
				required:'*必须选',
				digits:'数字'
			},
			'teamTel_ID':{
				digits:'数字',
       		 	maxlength:'最大为11位数'
			}
		}
	});

	
	function showData(data){
		if(data.ajaxRST=='1'){
			alert("保存成功！");
			$('#mainFrame',window.parent.document).attr('src','/ag/hmk/AidTeamAdd.jsp');
		}else{
			alert("保存失败！");
		}
	}
	
	$('#RESET_TEAM').click(function(){
		$('#mainFrame',window.parent.document).attr('src','/ag/hmk/AidTeamAdd.jsp');
	});
	
});